﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web;

namespace Widgetsphere.WebUtils
{
	public class PagingURL : URL
	{
		public PagingURL()
			: base()
		{
		}

		public PagingURL(string url)
			: base(url)
		{
		}

		public int PageOffset
		{
			get
			{
				int v;
				int.TryParse(this.Parameters.GetValue("po", "1"), out v);
				if (v < 1) v = 1;
				return v;
			}
			set { this.Parameters.SetValue("po", value.ToString()); }
		}

		public int RecordsPerPage
		{
			get
			{
				int v;
				int.TryParse(this.Parameters.GetValue("rpp", "10"), out v);
				if (v < 1) v = 10;
				return v;
			}
			set { this.Parameters.SetValue("rpp", value.ToString()); }
		}

		#region ICloneable Members

		public override object Clone()
		{
			var retval = new PagingURL();
			retval.Page = this.Page;

			//Need to create new objects not just add existing one
			foreach (var parameter in this.Parameters)
			{
				retval.Parameters.Add(new URLParameter(parameter.Name, parameter.Value));
			}
			
			return retval;
		}

		#endregion

	}
}